
class Templates < Controller
  def index e
    s = '<div class="ContentTemplates">'
    s << '<center><h1>Šablony obsahu</h1>'
    s << '<p>'
    s << Element.new(:a, '+ add', :href => e.link(:add), :class => 'button').to_s
    s << '</p>'
    s << '<div class="contentTemplateList">'
    ContentTemplate.all.each { |t|
      s << '<div class="contentTemplate">'+
        Element.new(:a,
          "<div class=\"icon\"><span>#{t.template_title}</span></div>"+
          "#{t.template_title}",
          :href => e.link('edit/'+t.id.to_s)).
        to_s+'</div>'
    }
    s << '</div><br style="clear:both"/>'
    s << '</center></div>'
    s
  end

  def add e
    if !e.request.post?
      @thing = ContentTemplate.new
      @thing.default_template
    end

    <<HTML
  <h1>Nová šablona</h1>
  #{@thing.creator_form(e)}
HTML
  end


  def edit e
    id = e.env[:unprocessed_tail][0]
    edit = ContentTemplate.get!(id)

    title = edit.template_title || edit.template_class

    <<HTML
  <h1>Upravit šablonu '#{title}'</h1>
  #{edit.creator_form e}
HTML
  end

end
